import request from '/@/utils/request';

enum Api {
	Page = '/api/sysUser/page',
	Detail = '/api/sysUser/detail',
	Add = '/api/sysUser/add',
	Update = '/api/sysUser/update',
	Delete = '/api/sysUser/delete',
	BatchDelete = '/api/sysUser/batchDelete',
	GetList = '/api/sysUser/getList',
}

// 用户实体
export interface SysUser {
	id: number;
	account: string;
	realName: string;
	nickName?: string;
	avatar?: string;
	phone?: string;
	email?: string;
	sex: number;
	age?: number;
	orgId: number;
	posId?: number;
	accountType: number;
	status: number;
	orderNo: number;
	tenantId: number;
	createTime: string;
	updateTime: string;
	createUserId: number;
	createUserName: string;
	updateUserId: number;
	updateUserName: string;
}

// 用户查询参数
export interface UserInput {
	page?: number;
	pageSize?: number;
	orgId?: number;
	tenantId?: number;
	account?: string;
	realName?: string;
	phone?: string;
}

// 用户管理接口服务
export const useSysUserApi = () => {
	return {
		// 分页查询用户
		page: (data: UserInput) =>
			request({
				url: Api.Page,
				method: 'post',
				data,
			}),
		// 查看用户详细
		detail: (id: number) =>
			request({
				url: Api.Detail,
				method: 'get',
				params: { id },
			}),
		// 获取用户列表（用于下拉框）
		getList: (params?: UserInput) =>
			request({
				url: Api.GetList,
				method: 'get',
				params,
			}),
		// 新增用户
		add: (data: any) =>
			request({
				url: Api.Add,
				method: 'post',
				data,
			}),
		// 更新用户
		update: (data: any) =>
			request({
				url: Api.Update,
				method: 'post',
				data,
			}),
		// 删除用户
		delete: (data: any) =>
			request({
				url: Api.Delete,
				method: 'post',
				data,
			}),
		// 批量删除用户
		batchDelete: (data: any) =>
			request({
				url: Api.BatchDelete,
				method: 'post',
				data,
			}),
	}
}

